Skip to content

Add deployment logs fetch support in SDK#132

Merged
anandj91 merged 6 commits intomainfrom
anandj/log_eg
Apr 9, 2026
Merged

Add deployment logs fetch support in SDK#132
anandj91 merged 6 commits intomainfrom
anandj/log_eg

Conversation

@anandj91
Copy link
Copy Markdown
Contributor

@anandj91 anandj91 commented Apr 9, 2026

Summary by CodeRabbit

  • New Features

    • Retrieve deployment revision metadata to view available revisions
    • Fetch deployment logs for specific revisions within customizable time windows with automatic pagination
  • Documentation

    • Added example script demonstrating log retrieval functionality

@anandj91
Copy link
Copy Markdown
Contributor Author

anandj91 commented Apr 9, 2026

@coderabbitai review

@anandj91 anandj91 requested a review from michaelshin April 9, 2026 14:43
@anandj91 anandj91 self-assigned this Apr 9, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 9, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Comment thread centml/sdk/api.py Outdated
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 9, 2026

Walkthrough

Two new CentMLClient methods enable retrieval of deployment revision metadata and logs with pagination support. An accompanying example script demonstrates usage, fetching logs within a configurable time window and formatting event output with timestamps.

Changes

Cohort / File(s) Summary
API Methods
centml/sdk/api.py
Added get_deployment_revisions() to fetch revision metadata and get_deployment_logs() with pagination support that accumulates events across multiple API calls using next_page_token.
Example Script
examples/sdk/get_deployment_logs.py
New example demonstrating log retrieval with configurable time window, pagination handling, and event formatting including timestamp conversion to ISO-8601.

Sequence Diagram

sequenceDiagram
    participant Client
    participant API
    participant Accumulator as Pagination Loop
    
    Client->>API: get_deployment_logs(deployment_id, revision_number, time_range)
    loop While next_page_token exists
        API-->>Accumulator: response {events, next_page_token}
        Accumulator->>Accumulator: Accumulate events
        alt next_page_token present
            Accumulator->>API: Request next page with token
        else No token
            Accumulator-->>Client: Return accumulated events
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hops with delight through the log-retrieval scene,
Pagination loops dancing, a beautiful machine!
Events accumulate, timestamps unfold,
Deployment revisions and stories retold. 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add deployment logs fetch support in SDK' directly and accurately summarizes the main change: adding two new methods to fetch deployment revisions and logs.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch anandj/log_eg

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
centml/sdk/api.py (1)

176-189: Add a repeated page-token guard to avoid potential infinite pagination loops.

If the backend ever returns the same non-empty next_page_token repeatedly, this loop will not terminate.

Suggested hardening
         all_events = []
         next_page_token = None
+        seen_page_tokens = set()

         while True:
             response = self._api.get_deployment_logs_v3_deployments_logs_v3_deployment_id_revision_number_get(
                 deployment_id=deployment_id,
                 revision_number=revision_number,
                 start_time=start_time,
                 end_time=end_time,
                 next_page_token=next_page_token,
                 start_from_head=start_from_head,
                 line_count=line_count,
             )
             all_events.extend(response.events)
             next_page_token = response.next_page_token
             if not next_page_token:
                 break
+            if next_page_token in seen_page_tokens:
+                raise RuntimeError("Pagination token repeated; aborting to avoid infinite loop")
+            seen_page_tokens.add(next_page_token)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@centml/sdk/api.py` around lines 176 - 189, The pagination loop using
next_page_token in the method that calls
_api.get_deployment_logs_v3_deployments_logs_v3_deployment_id_revision_number_get
should guard against repeated non-empty tokens to avoid infinite loops: track
seen tokens (e.g., a set seen_tokens) and after each response check if
next_page_token is non-empty and already in seen_tokens—if so, either break
and/or raise a descriptive exception; otherwise add the token to seen_tokens and
continue. Update the loop that extends all_events and assigns next_page_token to
incorporate this repeated-token check and fail-safe.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@centml/sdk/api.py`:
- Line 166: The parameter annotation for line_count is incorrect: it's typed as
int but defaults to None; update the signature to allow None by changing the
type to Optional[int] (and add from typing import Optional) or use the modern
union syntax (int | None) so the annotation matches the default; locate the
function/method that declares the line_count parameter in centml/sdk/api.py and
update its type accordingly.

---

Nitpick comments:
In `@centml/sdk/api.py`:
- Around line 176-189: The pagination loop using next_page_token in the method
that calls
_api.get_deployment_logs_v3_deployments_logs_v3_deployment_id_revision_number_get
should guard against repeated non-empty tokens to avoid infinite loops: track
seen tokens (e.g., a set seen_tokens) and after each response check if
next_page_token is non-empty and already in seen_tokens—if so, either break
and/or raise a descriptive exception; otherwise add the token to seen_tokens and
continue. Update the loop that extends all_events and assigns next_page_token to
incorporate this repeated-token check and fail-safe.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f78152e8-1621-409f-bc2b-c0aa21378087

📥 Commits

Reviewing files that changed from the base of the PR and between 1d67aca and 08a5eb2.

📒 Files selected for processing (2)
  • centml/sdk/api.py
  • examples/sdk/get_deployment_logs.py

Comment thread centml/sdk/api.py Outdated
Comment thread examples/sdk/get_deployment_logs.py
Comment thread examples/sdk/get_deployment_logs.py Outdated
@anandj91 anandj91 merged commit 6366b14 into main Apr 9, 2026
5 checks passed
@anandj91 anandj91 deleted the anandj/log_eg branch April 9, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants